<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>stacktrace_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_testing_stacktrace_test.js.html">stacktrace_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2009 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.testing.stacktraceTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.testing.stacktraceTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.functions&#39;);
<a name="line19"></a>goog.require(&#39;goog.string&#39;);
<a name="line20"></a>goog.require(&#39;goog.testing.ExpectedFailures&#39;);
<a name="line21"></a>goog.require(&#39;goog.testing.PropertyReplacer&#39;);
<a name="line22"></a>goog.require(&#39;goog.testing.StrictMock&#39;);
<a name="line23"></a>goog.require(&#39;goog.testing.asserts&#39;);
<a name="line24"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line25"></a>goog.require(&#39;goog.testing.stacktrace&#39;);
<a name="line26"></a>goog.require(&#39;goog.testing.stacktrace.Frame&#39;);
<a name="line27"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line28"></a>
<a name="line29"></a>var stubs = new goog.testing.PropertyReplacer();
<a name="line30"></a>var expectedFailures;
<a name="line31"></a>function setUpPage() {
<a name="line32"></a>  expectedFailures = new goog.testing.ExpectedFailures();
<a name="line33"></a>}
<a name="line34"></a>
<a name="line35"></a>function setUp() {
<a name="line36"></a>  stubs.set(goog.testing.stacktrace, &#39;isClosureInspectorActive_&#39;, function() {
<a name="line37"></a>    return false;
<a name="line38"></a>  });
<a name="line39"></a>}
<a name="line40"></a>
<a name="line41"></a>function tearDown() {
<a name="line42"></a>  stubs.reset();
<a name="line43"></a>  expectedFailures.handleTearDown();
<a name="line44"></a>}
<a name="line45"></a>
<a name="line46"></a>function testParseStackFrameInChrome() {
<a name="line47"></a>  var frameString = &#39;    at Error (unknown source)&#39;;
<a name="line48"></a>  var frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line49"></a>  var expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;Error&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;);
<a name="line50"></a>  assertObjectEquals(&#39;exception name only&#39;, expected, frame);
<a name="line51"></a>
<a name="line52"></a>  frameString = &#39;    at Object.assert (file:///.../asserts.js:29:10)&#39;;
<a name="line53"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line54"></a>  expected = new goog.testing.stacktrace.Frame(&#39;Object&#39;, &#39;assert&#39;, &#39;&#39;, &#39;&#39;,
<a name="line55"></a>      &#39;file:///.../asserts.js:29:10&#39;);
<a name="line56"></a>  assertObjectEquals(&#39;context object + function name + url&#39;, expected, frame);
<a name="line57"></a>
<a name="line58"></a>  frameString = &#39;    at http://www.example.com/jsunit.js:117:13&#39;;
<a name="line59"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line60"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;,
<a name="line61"></a>      &#39;http://www.example.com/jsunit.js:117:13&#39;);
<a name="line62"></a>  assertObjectEquals(&#39;url only&#39;, expected, frame);
<a name="line63"></a>
<a name="line64"></a>  frameString = &#39;    at [object Object].exec [as execute] (file:///foo)&#39;;
<a name="line65"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line66"></a>  expected = new goog.testing.stacktrace.Frame(&#39;[object Object]&#39;, &#39;exec&#39;,
<a name="line67"></a>      &#39;execute&#39;, &#39;&#39;, &#39;file:///foo&#39;);
<a name="line68"></a>  assertObjectEquals(&#39;function alias&#39;, expected, frame);
<a name="line69"></a>
<a name="line70"></a>  frameString = &#39;    at new Class (file:///foo)&#39;;
<a name="line71"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line72"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;new Class&#39;, &#39;&#39;, &#39;&#39;,
<a name="line73"></a>      &#39;file:///foo&#39;);
<a name="line74"></a>  assertObjectEquals(&#39;constructor call&#39;, expected, frame);
<a name="line75"></a>
<a name="line76"></a>  frameString = &#39;    at new &lt;anonymous&gt; (file:///foo)&#39;;
<a name="line77"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line78"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;new &lt;anonymous&gt;&#39;, &#39;&#39;, &#39;&#39;,
<a name="line79"></a>      &#39;file:///foo&#39;);
<a name="line80"></a>  assertObjectEquals(&#39;anonymous constructor call&#39;, expected, frame);
<a name="line81"></a>
<a name="line82"></a>  frameString = &#39;    at Array.forEach (native)&#39;;
<a name="line83"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line84"></a>  expected = new goog.testing.stacktrace.Frame(&#39;Array&#39;, &#39;forEach&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;);
<a name="line85"></a>  assertObjectEquals(&#39;native function call&#39;, expected, frame);
<a name="line86"></a>
<a name="line87"></a>  frameString = &#39;    at foo (eval at file://bar)&#39;;
<a name="line88"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line89"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;foo&#39;, &#39;&#39;, &#39;&#39;, &#39;file://bar&#39;);
<a name="line90"></a>  assertObjectEquals(&#39;eval&#39;, expected, frame);
<a name="line91"></a>}
<a name="line92"></a>
<a name="line93"></a>function testParseStackFrameInOpera() {
<a name="line94"></a>  var frameString = &#39;@&#39;;
<a name="line95"></a>  var frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line96"></a>  var expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;);
<a name="line97"></a>  assertObjectEquals(&#39;empty frame&#39;, expected, frame);
<a name="line98"></a>
<a name="line99"></a>  frameString = &#39;@javascript:console.log(Error().stack):1&#39;;
<a name="line100"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line101"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;,
<a name="line102"></a>      &#39;javascript:console.log(Error().stack):1&#39;);
<a name="line103"></a>  assertObjectEquals(&#39;javascript path only&#39;, expected, frame);
<a name="line104"></a>
<a name="line105"></a>  frameString = &#39;@file:///foo:42&#39;;
<a name="line106"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line107"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;,
<a name="line108"></a>      &#39;file:///foo:42&#39;);
<a name="line109"></a>  assertObjectEquals(&#39;path only&#39;, expected, frame);
<a name="line110"></a>
<a name="line111"></a>  // (function go() { throw Error() })()
<a name="line112"></a>  // var c = go; c()
<a name="line113"></a>  frameString = &#39;go([arguments not available])@&#39;;
<a name="line114"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line115"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;go&#39;, &#39;&#39;,
<a name="line116"></a>      &#39;([arguments not available])&#39;, &#39;&#39;);
<a name="line117"></a>  assertObjectEquals(&#39;name and empty path&#39;, expected, frame);
<a name="line118"></a>
<a name="line119"></a>  frameString = &#39;go([arguments not available])@file:///foo:42&#39;;
<a name="line120"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line121"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;go&#39;, &#39;&#39;,
<a name="line122"></a>      &#39;([arguments not available])&#39;, &#39;file:///foo:42&#39;);
<a name="line123"></a>  assertObjectEquals(&#39;name and path&#39;, expected, frame);
<a name="line124"></a>
<a name="line125"></a>  // (function() { throw Error() })()
<a name="line126"></a>  frameString =
<a name="line127"></a>      &#39;&lt;anonymous function&gt;([arguments not available])@file:///foo:42&#39;;
<a name="line128"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line129"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;&#39;, &#39;&#39;,
<a name="line130"></a>      &#39;([arguments not available])&#39;, &#39;file:///foo:42&#39;);
<a name="line131"></a>  assertObjectEquals(&#39;anonymous function&#39;, expected, frame);
<a name="line132"></a>
<a name="line133"></a>  // var b = {foo: function() { throw Error() }}
<a name="line134"></a>  frameString = &#39;&lt;anonymous function: foo&gt;()@file:///foo:42&#39;;
<a name="line135"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line136"></a>  expected = new goog.testing.stacktrace.Frame(
<a name="line137"></a>      &#39;&#39;, &#39;foo&#39;, &#39;&#39;, &#39;()&#39;, &#39;file:///foo:42&#39;);
<a name="line138"></a>  assertObjectEquals(&#39;object literal function&#39;, expected, frame);
<a name="line139"></a>
<a name="line140"></a>  // var c = {}; c.foo = function() { throw Error() }
<a name="line141"></a>  frameString = &#39;&lt;anonymous function: c.foo&gt;()@file:///foo:42&#39;;
<a name="line142"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line143"></a>  expected = new goog.testing.stacktrace.Frame(
<a name="line144"></a>      &#39;c&#39;, &#39;foo&#39;, &#39;&#39;, &#39;()&#39;, &#39;file:///foo:42&#39;);
<a name="line145"></a>  assertObjectEquals(&#39;named object literal function&#39;, expected, frame);
<a name="line146"></a>
<a name="line147"></a>  frameString = &#39;&lt;anonymous function: Foo.prototype.bar&gt;()@&#39;;
<a name="line148"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line149"></a>  expected = new goog.testing.stacktrace.Frame(
<a name="line150"></a>      &#39;Foo.prototype&#39;, &#39;bar&#39;, &#39;&#39;, &#39;()&#39;, &#39;&#39;);
<a name="line151"></a>  assertObjectEquals(&#39;prototype function&#39;, expected, frame);
<a name="line152"></a>
<a name="line153"></a>  frameString = &#39;&lt;anonymous function: goog.Foo.prototype.bar&gt;()@&#39;;
<a name="line154"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line155"></a>  expected = new goog.testing.stacktrace.Frame(
<a name="line156"></a>      &#39;goog.Foo.prototype&#39;, &#39;bar&#39;, &#39;&#39;, &#39;()&#39;, &#39;&#39;);
<a name="line157"></a>  assertObjectEquals(&#39;namespaced prototype function&#39;, expected, frame);
<a name="line158"></a>}
<a name="line159"></a>
<a name="line160"></a>// All test strings are parsed with the conventional and long
<a name="line161"></a>// frame algorithms.
<a name="line162"></a>function testParseStackFrameInFirefox() {
<a name="line163"></a>  var frameString = &#39;Error(&quot;Assertion failed&quot;)@:0&#39;;
<a name="line164"></a>  var frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line165"></a>  var expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;Error&#39;, &#39;&#39;,
<a name="line166"></a>      &#39;(&quot;Assertion failed&quot;)&#39;, &#39;&#39;);
<a name="line167"></a>  assertObjectEquals(&#39;function name + arguments&#39;, expected, frame);
<a name="line168"></a>
<a name="line169"></a>  frame = goog.testing.stacktrace.parseLongFirefoxFrame_(frameString);
<a name="line170"></a>  assertObjectEquals(&#39;function name + arguments&#39;, expected, frame);
<a name="line171"></a>
<a name="line172"></a>  frameString = &#39;()@file:///foo:42&#39;;
<a name="line173"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line174"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;()&#39;,
<a name="line175"></a>      &#39;file:///foo:42&#39;);
<a name="line176"></a>  assertObjectEquals(&#39;anonymous function&#39;, expected, frame);
<a name="line177"></a>
<a name="line178"></a>  frame = goog.testing.stacktrace.parseLongFirefoxFrame_(frameString);
<a name="line179"></a>  assertObjectEquals(&#39;anonymous function&#39;, expected, frame);
<a name="line180"></a>
<a name="line181"></a>  frameString = &#39;@javascript:alert(0)&#39;;
<a name="line182"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line183"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;,
<a name="line184"></a>      &#39;javascript:alert(0)&#39;);
<a name="line185"></a>  assertObjectEquals(&#39;anonymous function&#39;, expected, frame);
<a name="line186"></a>
<a name="line187"></a>  frame = goog.testing.stacktrace.parseLongFirefoxFrame_(frameString);
<a name="line188"></a>  assertObjectEquals(&#39;anonymous function&#39;, expected, frame);
<a name="line189"></a>}
<a name="line190"></a>
<a name="line191"></a>function testCanonicalizeFrame() {
<a name="line192"></a>  var frame = new goog.testing.stacktrace.Frame(&#39;&lt;window&gt;&#39;, &#39;foo&#39;, &#39;bar&#39;,
<a name="line193"></a>      &#39;(&quot;&lt;a&gt;\&#39;&amp;amp;&quot;)&#39;, &#39;http://x?a=1&amp;b=2:1&#39;);
<a name="line194"></a>  assertEquals(&#39;canonical stack frame, everything is escaped&#39;,
<a name="line195"></a>      &#39;&amp;lt;window&amp;gt;.foo(&amp;quot;&amp;lt;a&amp;gt;\&#39;&amp;amp;amp;&amp;quot;) &#39; +
<a name="line196"></a>      &#39;[as bar] at http://x?a=1&amp;amp;b=2:1&#39;, frame.toCanonicalString());
<a name="line197"></a>}
<a name="line198"></a>
<a name="line199"></a>function testCanonicalizeFrameWithClosureInspector() {
<a name="line200"></a>  stubs.set(goog.testing.stacktrace, &#39;isClosureInspectorActive_&#39;, function() {
<a name="line201"></a>    return true;
<a name="line202"></a>  });
<a name="line203"></a>
<a name="line204"></a>  var frame = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;foo&#39;, &#39;&#39;, &#39;()&#39;,
<a name="line205"></a>      &#39;http://x?a=1&amp;b=2:1&#39;);
<a name="line206"></a>  assertEquals(&#39;canonical stack frame with closure inspector link&#39;,
<a name="line207"></a>      &#39;foo() at &lt;a href=&quot;&quot; onclick=&quot;CLOSURE_INSPECTOR___.showLine(&#39; +
<a name="line208"></a>      &#39;\&#39;http://x?a=1&amp;amp;b=2:1\&#39;, \&#39;1\&#39;); return false&quot;&gt;&#39; +
<a name="line209"></a>      &#39;http://x?a=1&amp;amp;b=2:1&lt;&#39; + &#39;/a&gt;&#39;,
<a name="line210"></a>      frame.toCanonicalString());
<a name="line211"></a>}
<a name="line212"></a>
<a name="line213"></a>function testDeobfuscateFunctionName() {
<a name="line214"></a>  goog.testing.stacktrace.setDeobfuscateFunctionName(function(name) {
<a name="line215"></a>    return name.replace(/\$/g, &#39;.&#39;);
<a name="line216"></a>  });
<a name="line217"></a>
<a name="line218"></a>  var frame = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;a$b$c&#39;, &#39;d$e&#39;, &#39;&#39;, &#39;&#39;);
<a name="line219"></a>  assertEquals(&#39;deobfuscated function name&#39;, &#39;a.b.c [as d.e]&#39;,
<a name="line220"></a>      frame.toCanonicalString());
<a name="line221"></a>}
<a name="line222"></a>
<a name="line223"></a>function testFramesToString() {
<a name="line224"></a>  var normalFrame = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;foo&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;);
<a name="line225"></a>  var anonFrame = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;);
<a name="line226"></a>  var frames = [normalFrame, anonFrame, null, anonFrame];
<a name="line227"></a>  var stack = goog.testing.stacktrace.framesToString_(frames);
<a name="line228"></a>  assertEquals(&#39;framesToString&#39;, &#39;&gt; foo\n&gt; anonymous\n&gt; (unknown)\n&#39;, stack);
<a name="line229"></a>}
<a name="line230"></a>
<a name="line231"></a>function testFollowCallChain() {
<a name="line232"></a>  var func = function(var_args) {
<a name="line233"></a>    return goog.testing.stacktrace.followCallChain_();
<a name="line234"></a>  };
<a name="line235"></a>
<a name="line236"></a>  // Created a fake type with a toString method.
<a name="line237"></a>  function LocalType() {};
<a name="line238"></a>  LocalType.prototype.toString = function() {
<a name="line239"></a>    return &#39;sg&#39;;
<a name="line240"></a>  };
<a name="line241"></a>
<a name="line242"></a>  // Create a mock with no expectations.
<a name="line243"></a>  var mock = new goog.testing.StrictMock(LocalType);
<a name="line244"></a>
<a name="line245"></a>  mock.$replay();
<a name="line246"></a>
<a name="line247"></a>  var frames = func(undefined, null, false, 0, &#39;&#39;, {}, goog.nullFunction,
<a name="line248"></a>      mock, new LocalType);
<a name="line249"></a>
<a name="line250"></a>  // Opera before version 10 doesn&#39;t support the caller attribute. In that
<a name="line251"></a>  // browser followCallChain_() returns empty stack trace.
<a name="line252"></a>  expectedFailures.expectFailureFor(goog.userAgent.OPERA &amp;&amp;
<a name="line253"></a>      !goog.userAgent.isVersionOrHigher(&#39;10&#39;));
<a name="line254"></a>  try {
<a name="line255"></a>    assertTrue(&#39;The stack trace consists of &gt;=2 frames&#39;, frames.length &gt;= 2);
<a name="line256"></a>  } catch (e) {
<a name="line257"></a>    expectedFailures.handleException(e);
<a name="line258"></a>  }
<a name="line259"></a>
<a name="line260"></a>  if (frames.length &gt;= 2) {
<a name="line261"></a>    assertEquals(&#39;innermost function is anonymous&#39;, &#39;&#39;, frames[0].getName());
<a name="line262"></a>    // There are white space differences how browsers convert functions to
<a name="line263"></a>    // strings.
<a name="line264"></a>    var expected = &#39;(undefined,null,false,0,&quot;&quot;,[objectObject],function(){},&#39; +
<a name="line265"></a>        &#39;goog.testing.Mock,sg)&#39;;
<a name="line266"></a>    assertEquals(&#39;arguments of the innermost function (ignoring whitespaces)&#39;,
<a name="line267"></a>        expected, frames[0].args_.replace(/\s/g, &#39;&#39;));
<a name="line268"></a>    assertEquals(&#39;test function name&#39;, &#39;testFollowCallChain&#39;,
<a name="line269"></a>        frames[1].getName());
<a name="line270"></a>  }
<a name="line271"></a>
<a name="line272"></a>  mock.$verify();
<a name="line273"></a>}
<a name="line274"></a>
<a name="line275"></a>// Create a stack trace string with one modest record and one long record,
<a name="line276"></a>// Verify that all frames are parsed. The length of the long arg is set
<a name="line277"></a>// to blow Firefox 3x&#39;s stack if put through a RegExp.
<a name="line278"></a>function testParsingLongStackTrace() {
<a name="line279"></a>  var longArg = goog.string.buildString(
<a name="line280"></a>      &#39;(&#39;, goog.string.repeat(&#39;x&#39;, 1000000), &#39;)&#39;);
<a name="line281"></a>  var stackTrace = goog.string.buildString(
<a name="line282"></a>      &#39;shortFrame()@:0\n&#39;,
<a name="line283"></a>      &#39;longFrame&#39;,
<a name="line284"></a>      longArg,
<a name="line285"></a>      &#39;@http://google.com/somescript:0\n&#39;);
<a name="line286"></a>  var frames = goog.testing.stacktrace.parse_(stackTrace);
<a name="line287"></a>  assertEquals(&#39;number of returned frames&#39;, 2, frames.length);
<a name="line288"></a>  var expected = new goog.testing.stacktrace.Frame(
<a name="line289"></a>      &#39;&#39;, &#39;shortFrame&#39;, &#39;&#39;, &#39;()&#39;, &#39;&#39;);
<a name="line290"></a>  assertObjectEquals(&#39;short frame&#39;, expected, frames[0]);
<a name="line291"></a>
<a name="line292"></a>  expected = new goog.testing.stacktrace.Frame(
<a name="line293"></a>      &#39;&#39;, &#39;longFrame&#39;, &#39;&#39;, longArg, &#39;http://google.com/somescript:0&#39;);
<a name="line294"></a>  assertObjectEquals(&#39;exception name only&#39;, expected, frames[1]);
<a name="line295"></a>}
<a name="line296"></a>
<a name="line297"></a>function testParseStackFrameInIE10() {
<a name="line298"></a>  var frameString = &#39;   at foo (http://bar:4000/bar.js:150:3)&#39;;
<a name="line299"></a>  var frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line300"></a>  var expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;foo&#39;, &#39;&#39;, &#39;&#39;,
<a name="line301"></a>      &#39;http://bar:4000/bar.js:150:3&#39;);
<a name="line302"></a>  assertObjectEquals(&#39;name and path&#39;, expected, frame);
<a name="line303"></a>
<a name="line304"></a>  frameString = &#39;   at Anonymous function (http://bar:4000/bar.js:150:3)&#39;;
<a name="line305"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line306"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;Anonymous function&#39;, &#39;&#39;, &#39;&#39;,
<a name="line307"></a>      &#39;http://bar:4000/bar.js:150:3&#39;);
<a name="line308"></a>  assertObjectEquals(&#39;Anonymous function&#39;, expected, frame);
<a name="line309"></a>
<a name="line310"></a>  frameString = &#39;   at Global code (http://bar:4000/bar.js:150:3)&#39;;
<a name="line311"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line312"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;Global code&#39;, &#39;&#39;, &#39;&#39;,
<a name="line313"></a>      &#39;http://bar:4000/bar.js:150:3&#39;);
<a name="line314"></a>  assertObjectEquals(&#39;Global code&#39;, expected, frame);
<a name="line315"></a>
<a name="line316"></a>  frameString = &#39;   at foo (eval code:150:3)&#39;;
<a name="line317"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line318"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;foo&#39;, &#39;&#39;, &#39;&#39;,
<a name="line319"></a>      &#39;eval code:150:3&#39;);
<a name="line320"></a>  assertObjectEquals(&#39;eval code&#39;, expected, frame);
<a name="line321"></a>
<a name="line322"></a>  frameString = &#39;   at eval code (eval code:150:3)&#39;;
<a name="line323"></a>  frame = goog.testing.stacktrace.parseStackFrame_(frameString);
<a name="line324"></a>  expected = new goog.testing.stacktrace.Frame(&#39;&#39;, &#39;eval code&#39;, &#39;&#39;, &#39;&#39;,
<a name="line325"></a>      &#39;eval code:150:3&#39;);
<a name="line326"></a>  assertObjectEquals(&#39;nested eval&#39;, expected, frame);
<a name="line327"></a>}
<a name="line328"></a>
<a name="line329"></a>// Verifies that retrieving the stack trace works when the &#39;stack&#39; field of an
<a name="line330"></a>// exception contains an array of CallSites instead of a string. This is the
<a name="line331"></a>// case when running in a lightweight V8 runtime (for instance, in gjstests),
<a name="line332"></a>// as opposed to a browser environment.
<a name="line333"></a>function testGetStackFrameWithV8CallSites() {
<a name="line334"></a>  // A function to create V8 CallSites. Note that CallSite is an extern and thus
<a name="line335"></a>  // cannot be mocked with closure mocks.
<a name="line336"></a>  function createCallSite(functionName, fileName, lineNumber, colNumber) {
<a name="line337"></a>    return {
<a name="line338"></a>      getFunctionName: goog.functions.constant(functionName),
<a name="line339"></a>      getFileName: goog.functions.constant(fileName),
<a name="line340"></a>      getLineNumber: goog.functions.constant(lineNumber),
<a name="line341"></a>      getColumnNumber: goog.functions.constant(colNumber)
<a name="line342"></a>    };
<a name="line343"></a>  }
<a name="line344"></a>
<a name="line345"></a>  // Mock the goog.testing.stacktrace.getStack_ function, which normally
<a name="line346"></a>  // triggers an exception for the purpose of reading and returning its stack
<a name="line347"></a>  // trace. Here, pretend that V8 provided an array of CallSites instead of the
<a name="line348"></a>  // string that browsers provide.
<a name="line349"></a>  stubs.set(goog.testing.stacktrace, &#39;getNativeStack_&#39;, function() {
<a name="line350"></a>    return [
<a name="line351"></a>      createCallSite(&#39;fn1&#39;, &#39;file1&#39;, 1, 2),
<a name="line352"></a>      createCallSite(&#39;fn2&#39;, &#39;file2&#39;, 3, 4),
<a name="line353"></a>      createCallSite(&#39;fn3&#39;, &#39;file3&#39;, 5, 6)
<a name="line354"></a>    ];
<a name="line355"></a>  });
<a name="line356"></a>
<a name="line357"></a>  // Retrieve the stacktrace. This should translate the array of CallSites into
<a name="line358"></a>  // a single multi-line string.
<a name="line359"></a>  var stackTrace = goog.testing.stacktrace.get();
<a name="line360"></a>
<a name="line361"></a>  // Make sure the stack trace was translated correctly.
<a name="line362"></a>  var frames = stackTrace.split(&#39;\n&#39;);
<a name="line363"></a>  assertEquals(frames[0], &#39;&gt; fn1 at file1:1:2&#39;);
<a name="line364"></a>  assertEquals(frames[1], &#39;&gt; fn2 at file2:3:4&#39;);
<a name="line365"></a>  assertEquals(frames[2], &#39;&gt; fn3 at file3:5:6&#39;);
<a name="line366"></a>}
</pre>


</body>
</html>
